package entity_controllers;


public class OptionManager {
	private Option[] options = new Option[2];
	private int counter = 0;

	public boolean hasOptions() {
		for (int i = 0; i < options.length; i++) {
			if (options[i] != null)
				if (options[i].isEnabled())
					return true;
		}
		return false;
	}

	public Option getOption(Class<?> c) {
		for (int i = 0; i < options.length; i++) {
			if (options[i]
					.getClass()
					.equals(c)) {
				return options[i];
			}
		}
		System.out.println("Player did not contain option " + c);
		return null;
	}

	public Option[] getOptions() {
		return options;
	}

	public Option[] getAvailableOptions(){
		Option[] tempOptions = new Option[options.length];
		Option[] availableOptions;
		int a = 0;
		for (int o = 0; o < options.length; o++) {
			if(options[o] != null && options[o].isEnabled()){
				tempOptions[a++] = options[o];
			}
		}
		availableOptions = new Option[a];
		for (int i = 0; i < availableOptions.length; i++) {
			availableOptions[i] = tempOptions[i];
		}
		return availableOptions;
	}
	
	
	public void reset() {
		for (int i = 0; i < options.length; i++) {
			if (options[i] != null)
				options[i].reset();
		}
	}

	public void addOption(Option option) {
		if (counter >= options.length) {
			Option[] newOptions = new Option[options.length * 2];
			for (int i = 0; i < options.length; i++) {
				newOptions[i] = options[i];
			}
			options = newOptions;
		}
		options[counter++] = option;
	}

}